package rs.fon.is.music.services.rest.parsers;

import rs.fon.is.music.domain.MusicRecording;

import com.google.gson.JsonObject;

public class MusicRecordingJsonParser {

	public static JsonObject serialize(MusicRecording recording) {
		JsonObject recordingJson = new JsonObject();
		String uri = recording.getUri().toString();
		recordingJson.addProperty("uri", uri);
		recordingJson.addProperty("url", recording.getUrl().toString());
		recordingJson.addProperty("name", recording.getName());
		recordingJson.addProperty("interactionCount", recording.getInteractionCount());
		if(recording.getKeywords().size()>0){
			String keywords = "";
			for (String keyword : recording.getKeywords()) {
				keywords += keyword + ", ";
			}
			recordingJson.addProperty("keywords", keywords.substring(0, keywords.length()-2));
		}
		String groupID = recording.getArtist().getUri().toString().substring(recording.getArtist().getUri().toString().lastIndexOf('/')+1);
		String albumID = recording.getAlbum().getUri().toString().substring(recording.getAlbum().getUri().toString().lastIndexOf('/')+1);
		recordingJson.addProperty("byArtist", "http://localhost:8080/Music/api/groups/" + groupID);
		recordingJson.addProperty("inAlbum", "http://localhost:8080/Music/api/albums/" + albumID);
		return recordingJson;
	}

}
